package com.googlecode.perfectable.visuable.visual.custom;

import com.googlecode.perfectable.visuable.renderer.ElementRenderer;
import com.googlecode.perfectable.visuable.renderer.VisualRenderer;
import com.googlecode.perfectable.visuable.visual.Visual;

public class HeadVisual implements Visual {
	// MARK handle stadnard HTML head elements like "title", "link", "meta"

	public static final String ELEMENT_NAME = "head";

	private final Iterable<ScriptVisual> frameworkScripts = ScriptVisual.createFramework();

	private HeadVisual() {
	}

	public static HeadVisual create() {
		return new HeadVisual();
	}

	@Override
	public void render(VisualRenderer painter) {
		try(ElementRenderer elementRenderer = painter.element(ELEMENT_NAME)) {
			try(VisualRenderer childrenRenderer = elementRenderer.children()) {
				for(ScriptVisual visual : this.frameworkScripts) {
					visual.render(childrenRenderer);
				}
			}
		}
	}

}
